package com.qf.main.pharmacy.controller;

import com.mysql.cj.x.protobuf.MysqlxCrud;
import com.qf.common.base.result.ResponseResult;
import com.qf.main.pharmacy.common.vo.ClassificationCountVo;
import com.qf.main.pharmacy.common.vo.OrderAnalyseListVo;
import com.qf.main.pharmacy.common.vo.OrderAnalyseVo;
import com.qf.main.pharmacy.common.vo.OrderEchartsVo;
import com.qf.main.pharmacy.service.AddressService;
import com.qf.main.pharmacy.service.AnalyseService;
import com.qf.main.pharmacy.service.OrderMallService;
import com.qf.main.pharmacy.service.OrderService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author chengqiang
 * @Create 2024-02-26-1:32
 * @Description:
 */
@RestController
@RequestMapping("/analyse")
@CrossOrigin
@Api(tags = "数据分析模块")
public class AnalyseController {

    @Resource
    private AnalyseService analyseService;

    @GetMapping("/order/mall")
    public ResponseResult<List<OrderAnalyseVo>> listOrderAnalyse(){
        List<OrderAnalyseVo> orderAnalyseVos = analyseService.listOrderAnalyse();
        return  ResponseResult.success(orderAnalyseVos);
    }
    @GetMapping("/order")
    public ResponseResult<OrderAnalyseListVo> getOrderAnalyse(){
        OrderAnalyseListVo orderAnalyseList = analyseService.getOrderAnalyseList();
        return  ResponseResult.success(orderAnalyseList);
    }
    @GetMapping("/echarts/line")
    public ResponseResult<OrderEchartsVo> getMapLineList(){
        List<Map<String, Object>> maps1 = analyseService.countDataPerDayLast7Days();
        List<Map<String, Object>> maps2 = analyseService.countCancelDataPerDayLast7Days();
        List<Map<String, Object>> maps3 = analyseService.countNoPayCancelDataPerDayLast7Days();
        List<Map<String, Object>> maps4 = analyseService.countPayCancelDataPerDayLast7Days();
        OrderEchartsVo orderEchartsVo = OrderEchartsVo.builder()
                .countDataPerDayLast7Days(maps1)
                .countCancelDataPerDayLast7Days(maps2)
                .countNoPayDataPerDayLast7Days(maps3)
                .countPayDataPerDayLast7Days(maps4).build();
        return  ResponseResult.success(orderEchartsVo);
    }
    @GetMapping("/echarts/pie")
    public ResponseResult<List<ClassificationCountVo>> getMapPieList(){
        List<ClassificationCountVo> maps = analyseService.classificationCount();
        return  ResponseResult.success(maps);
    }
    @GetMapping("/echarts/bar")
    public ResponseResult<List<ClassificationCountVo>> getMapBarList(){
        List<ClassificationCountVo> maps = analyseService.classificationMallCount();
        return  ResponseResult.success(maps);
    }
}
